#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
 
int main()
{
   int      f[2];
   pid_t    p;
   char     ms[100];
   int      id;
   
   if(pipe(f)<0)
     perror("PIPE ERROR");
   if( (p=fork()) < 0)
      perror("fork error");
   else if(p==0)
   {
      close(f[0]);
      char s1[]="is sending a message to parent!";

      //get the child 
      int d=getpid(); 
      printf("child:%d\n",getpid());
      write(f[1],s1,sizeof(s1));
      write(f[1],&d,sizeof(int));

   }  
   else
   {
      close(f[1]);
      read(f[0],ms,sizeof("is sending a message to parent!"));
      puts(ms);
      read(f[0],&id,sizeof(int));
      printf("%d\n",id);
   }
   return 0;
} 
